home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / NDK / NDK_1.3 / Read-Me1.3 / Printer1.3 / Driver.Examples / src / hp / render.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-01  |  4.1 KB  |  168 lines

  1. /*
  2.     HP_LaserJet driver.
  3.     David Berezowski - May/87.
  4. */
  5.  
  6. #include <exec/types.h>
  7. #include <exec/nodes.h>
  8. #include <exec/lists.h>
  9. #include <exec/memory.h>
  10. #include "../printer/prtbase.h"
  11. #include "../printer/printer.h"
  12.  
  13. #define NUMSTARTCMD    7    /* # of cmd bytes before binary data */
  14. #define NUMENDCMD    0    /* # of cmd bytes after binary data */
  15. #define NUMTOTALCMD (NUMSTARTCMD + NUMENDCMD)    /* total of above */
  16.  
  17. extern SetDensity();
  18. /*
  19.     00-04    \033&l0L    perf skip mode off
  20.     05-11    \033*t075R    set raster graphics resolution (dpi)
  21.     12-16    \033*r0A    start raster graphics
  22. */
  23. char StartCmd[17] = "\033&l0L\033*t075R\033*r0A";
  24.  
  25. Render(ct, x, y, status)
  26. long ct, x, y, status;
  27. {
  28.     extern void *AllocMem(), FreeMem();
  29.  
  30.     extern struct PrinterData *PD;
  31.     extern struct PrinterExtendedData *PED;
  32.  
  33.     static UWORD RowSize, BufSize, TotalBufSize, dataoffset;
  34.     static UWORD huns, tens, ones; /* used to program buffer size */
  35.     UBYTE *ptr, *ptrstart;
  36.     int i, err;
  37.  
  38.     switch(status) {
  39.         case 0 : /* Master Initialization */
  40.             /*
  41.                 ct    - pointer to IODRPReq structure.
  42.                 x    - width of printed picture in pixels.
  43.                 y    - height of printed picture in pixels.
  44.             */
  45.             RowSize = (x + 7) / 8;
  46.             BufSize = RowSize + NUMTOTALCMD;
  47.             TotalBufSize = BufSize * 2;
  48.             PD->pd_PrintBuf = AllocMem(TotalBufSize, MEMF_PUBLIC);
  49.             if (PD->pd_PrintBuf == NULL) {
  50.                 err = PDERR_BUFFERMEMORY; /* no mem */
  51.             }
  52.             else {
  53.                 ptr = PD->pd_PrintBuf;
  54.                 *ptr++ = 27;
  55.                 *ptr++ = '*';
  56.                 *ptr++ = 'b';    /* transfer raster graphics */
  57.                 *ptr++ = huns | '0';
  58.                 *ptr++ = tens | '0';
  59.                 *ptr++ = ones | '0';    /* printout width */
  60.                 *ptr = 'W';        /* terminator */
  61.                 ptr = &PD->pd_PrintBuf[BufSize];
  62.                 *ptr++ = 27;
  63.                 *ptr++ = '*';
  64.                 *ptr++ = 'b';    /* transfer raster graphics */
  65.                 *ptr++ = huns | '0';
  66.                 *ptr++ = tens | '0';
  67.                 *ptr++ = ones | '0';    /* printout width */
  68.                 *ptr = 'W';        /* terminator */
  69.                 dataoffset = NUMSTARTCMD;
  70.             /* perf skip mode off, set dpi, start raster gfx */
  71.                 err = (*(PD->pd_PWrite))(StartCmd, 17);
  72.             }
  73.             break;
  74.  
  75.         case 1 : /* Scale, Dither and Render */
  76.             /*
  77.                 ct    - pointer to PrtInfo structure.
  78.                 x    - 0.
  79.                 y    - row # (0 to Height - 1).
  80.             */
  81.             Transfer(ct, y, &PD->pd_PrintBuf[dataoffset]);
  82.             err = PDERR_NOERR; /* all ok */
  83.             break;
  84.  
  85.         case 2 : /* Dump Buffer to Printer */
  86.             /*
  87.                 ct    - 0.
  88.                 x    - 0.
  89.                 y    - # of rows sent (1 to NumRows).
  90.  
  91.                 White-space strip.
  92.             */
  93.             i = RowSize;
  94.             ptrstart = &PD->pd_PrintBuf[dataoffset - NUMSTARTCMD];
  95.             ptr = ptrstart + NUMSTARTCMD + i - 1;
  96.             while (i > 0 && *ptr == 0) {
  97.                 i--;
  98.                 ptr--;
  99.             }
  100.             ptr = ptrstart + 3; /* get ptr to density info */
  101.             *ptr++ = (huns = i / 100) | '0';
  102.             *ptr++ = (i - huns * 100) / 10 | '0';
  103.             *ptr = i % 10 | '0'; /* set printout width */
  104.             err = (*(PD->pd_PWrite))(ptrstart, i + NUMTOTALCMD);
  105.             if (err == PDERR_NOERR) {
  106.                 dataoffset = (dataoffset == NUMSTARTCMD ?
  107.                     BufSize : 0) + NUMSTARTCMD;
  108.             }
  109.             break;
  110.  
  111.         case 3 : /* Clear and Init Buffer */
  112.             /*
  113.                 ct    - 0.
  114.                 x    - 0.
  115.                 y    - 0.
  116.             */
  117.             ptr = &PD->pd_PrintBuf[dataoffset];
  118.             i = RowSize;
  119.             do {
  120.                 *ptr++ = 0;
  121.             } while (--i);
  122.             break;
  123.  
  124.         case 4 : /* Close Down */
  125.             /*
  126.                 ct    - error code.
  127.                 x    - io_Special flag from IODRPReq struct
  128.                 y    - 0.
  129.             */
  130.             err = PDERR_NOERR; /* assume all ok */
  131.             /* if user did not cancel the print */
  132.             if (ct != PDERR_CANCEL) {
  133.                 /* end raster graphics, perf skip mode on */
  134.                 if ((err = (*(PD->pd_PWrite))
  135.                     ("\033*rB\033&l1L", 9)) == PDERR_NOERR) {
  136.                     /* if want to unload paper */
  137.                     if (!(x & SPECIAL_NOFORMFEED)) {
  138.                         /* eject paper */
  139.                         err = (*(PD->pd_PWrite))
  140.                             ("\014", 1);
  141.                     }
  142.                 }
  143.             }
  144.             /*
  145.                 flag that there is no alpha data waiting that
  146.                 needs a formfeed (since we just did one)
  147.             */
  148.             PED->ped_PrintMode = 0;
  149.              /* wait for both buffers to empty */
  150.             (*(PD->pd_PBothReady))();
  151.             if (PD->pd_PrintBuf != NULL) {
  152.                 FreeMem(PD->pd_PrintBuf, TotalBufSize);
  153.             }
  154.             break;
  155.  
  156.         case 5 : /* Pre-Master Initialization */
  157.             /*
  158.                 ct    - 0 or pointer to IODRPReq structure.
  159.                 x    - io_Special flag from IODRPReq struct
  160.                 y    - 0.
  161.             */
  162.             /* select density */
  163.             SetDensity(x & SPECIAL_DENSITYMASK);
  164.             break;
  165.     }
  166.     return(err);
  167. }
  168.